var MyStack = function() {
    this.queue1 = [];
    this.queue2 = [];
};

/** 
 * @param {number} x
 * @return {void}
 */
MyStack.prototype.push = function(x) {
    this.queue1.unshift(x)
};

/**
 * @return {number}
 */
MyStack.prototype.pop = function() {
    if(!this.empty()){
        while(this.queue1.length>1){
            this.queue2.unshift(this.queue1.pop())
        }
        let res = this.queue1.pop()
    
        while(this.queue2.length){
          this.queue1.unshift(this.queue2.pop())
        }
        this.queue1.unshift(res)
        return res
    }
    return undefined
};

/**
 * @return {number}
 */
MyStack.prototype.top = function() {
    while(this.queue1.length>1){
        this.queue2.unshift(this.queue1.pop())
    }
    let res = this.queue1.pop()
    
    while(this.queue2.length){
        this.queue1.unshift(this.queue2.pop())
    }
    this.queue1.unshift(res)
    return res
};

/**
 * @return {boolean}
 */
MyStack.prototype.empty = function() {
    return !this.queue1.length
};

/**
 * Your MyStack object will be instantiated and called as such:
 * var obj = new MyStack()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.empty()
 */